home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n05.arc / TRYFTRIG.ASM < prev    next >
Assembly Source File  |  1990-02-13  |  7KB  |  207 lines

  1.         title   TRYFTRIG --- Demo of FTRIG routines
  2.         page    55,132
  3.  
  4. ; TRYFTRIG.ASM --- Interactive Demo of FTRIG routines
  5. ;
  6. ; To exit from the program, push <Enter>
  7. ; alone at the "Enter a number" prompt.
  8. ;
  9. ; (C) 1989 Ray Duncan
  10. ;
  11. ; Build with:   MASM FTOA;
  12. ;               MASM ATOF;
  13. ;               MASM FTRIG;
  14. ;               MASM FALOG;
  15. ;               MASM INIT87;
  16. ;               MASM TRYFTRIG;
  17. ;               LINK TRYFTRIG+FTOA+ATOF+FTRIG+FALOT+INIT87;
  18. ;
  19.  
  20. cr      equ     0dh                     ; ASCII carriage return
  21. lf      equ     0ah                     ; ASCII line feed
  22.  
  23. stdin   equ     0                       ; standard input handle
  24. stdout  equ     1                       ; standard output handle
  25.  
  26. DGROUP  group   _DATA,STACK
  27.  
  28. _TEXT   segment word public 'CODE'
  29.  
  30.         assume  cs:_TEXT,ds:DGROUP
  31.  
  32.         extrn   ATOF:near               ; ASCII to floating point
  33.         extrn   FTOA:near               ; floating point to ASCII
  34.         extrn   FSIN:near               ; 80x87 sine
  35.         extrn   FCOS:near               ; 80x87 cosine
  36.         extrn   FTAN:near               ; 80x87 tangent
  37.         extrn   INIT87:near             ; initialize numeric coprocessor
  38.  
  39. main    proc    near
  40.  
  41.         mov     ax,DGROUP               ; make our data segment
  42.         mov     ds,ax                   ; addressable...
  43.         mov     es,ax
  44.         
  45.         mov     ax,03ffh                ; initialize coprocessor
  46.         call    init87                  ; rounding = nearest or even
  47.                                         ; precision = 64 bits
  48.                                         ; mask all exceptions
  49.  
  50.         jz      main1                   ; jump, coprocessor present
  51.  
  52.         mov     dx,offset errmsg        ; coprocessor absent,
  53.         mov     cx,err_len              ; display error message
  54.         call    pmsg                    ; and terminate program
  55.         jmp     main3
  56.  
  57. main1:  mov     dx,offset signon        ; display sign-on message
  58.         mov     cx,so_len
  59.         call    pmsg
  60.  
  61. main2:  mov     dx,offset prompt1       ; display prompt
  62.         mov     cx,p1_len
  63.         call    pmsg                   
  64.  
  65.         mov     dx,offset inbuff        ; read keyboard entry
  66.         mov     cx,80                   ; from the user...
  67.         mov     bx,stdin                ; standard input handle
  68.         mov     ah,3fh                  ; funct. 3FH = read
  69.         int     21h                     ; transfer to MS-DOS
  70.  
  71.         cmp     byte ptr inbuff,cr      ; was anything entered?
  72.         jne     main4                   ; yes, proceed
  73.  
  74. main3:  mov     ax,4c00h                ; no, exit to MS-DOS
  75.         int     21h
  76.  
  77. main4:  mov     si,offset inbuff        ; convert convert user's 
  78.         call    atof                    ; input to binary in ST(0)
  79.  
  80.         fld     st(0)                   ; duplicate the value
  81.         fmul    qword ptr deg2rad       ; convert it to radians 
  82.         fstp    qword ptr arg           ; save angle in radians
  83.  
  84.         mov     al,' '                  ; clear output format areas
  85.         mov     di,offset disp1 
  86.         mov     cx,30
  87.         rep stosb
  88.         mov     di,offset disp2
  89.         mov     cx,30
  90.         rep stosb
  91.         mov     di,offset disp3
  92.         mov     cx,30
  93.         rep stosb
  94.         mov     di,offset disp4
  95.         mov     cx,30
  96.         rep stosb
  97.         mov     di,offset disp5
  98.         mov     cx,30
  99.         rep stosb
  100.  
  101.         mov     si,offset disp1         ; convert degrees to ASCII
  102.         call    ftoa
  103.  
  104.         fld     qword ptr arg           ; convert radians to ASCII
  105.         mov     si,offset disp2
  106.         call    ftoa
  107.  
  108.         fld     qword ptr arg           ; load radians
  109.         call    fsin                    ; calculate sine
  110.         mov     si,offset disp3         ; convert sine to ASCII
  111.         call    ftoa
  112.  
  113.         fld     qword ptr arg           ; load radians
  114.         call    fcos                    ; calculate cosine
  115.         mov     si,offset disp4         ; convert cosine to ASCII
  116.         call    ftoa
  117.  
  118.         fld     qword ptr arg           ; load radians
  119.         call    ftan                    ; calculate tangent
  120.         mov     si,offset disp5         ; convert tangent to ASCII
  121.         call    ftoa
  122.  
  123.         mov     dx,offset display       ; display original angle,
  124.         mov     cx,d_len                ; angle in radians, sine,
  125.         call    pmsg                    ; cosine, and tangent
  126.  
  127.         jmp     main2                   ; do it again...
  128.  
  129. main    endp
  130.  
  131.  
  132. pmsg    proc    near                    ; display message on stdout
  133.                                         ; call with 
  134.                                         ; DS:DX = message address
  135.                                         ; CX    = message length
  136.  
  137.         mov     bx,stdout               ; standard output handle
  138.         mov     ah,40h                  ; function 40h = write
  139.         int     21h                     ; transfer to MS-DOS
  140.         ret                             ; return to caller
  141.  
  142. pmsg    endp
  143.  
  144. _TEXT   ends
  145.  
  146.  
  147. _DATA   segment word public 'DATA'
  148.  
  149. signon  db      cr,lf
  150.         db      'Demo Program for Coprocessor Trig Routines.'
  151.         db      cr,lf,lf
  152.         db      'Specify angle in degrees as a signed decimal value'
  153.         db      cr,lf
  154.         db      'followed by the <Enter> key.  The sine, cosine,'
  155.         db      cr,lf
  156.         db      'and tangent of the value are displayed.'
  157.         db      cr,lf,lf
  158.         db      'Press <Enter> alone at any prompt to exit.'
  159.         db      cr,lf
  160.  
  161. so_len  equ     $-signon
  162.  
  163. prompt1 db      cr,lf
  164.         db      'Enter angle (degrees): '
  165. p1_len  equ     $-prompt1
  166.  
  167. display db      cr,lf
  168.         db      'Degrees:  '
  169. disp1   db      30 dup (' ')
  170.         db      cr,lf
  171.         db      'Radians:  '
  172. disp2   db      30 dup (' ')
  173.         db      cr,lf
  174.         db      'Sine:     '
  175. disp3   db      30 dup (' ')
  176.         db      cr,lf
  177.         db      'Cosine:   '
  178. disp4   db      30 dup (' ')
  179.         db      cr,lf
  180.         db      'Tangent:  '
  181. disp5   db      30 dup (' ')
  182.         db      cr,lf
  183. d_len   equ     $-display
  184.  
  185. errmsg  db      cr,lf
  186.         db      'No 80x87 coprocessor found!'
  187.         db      cr,lf
  188. err_len equ     $-errmsg
  189.  
  190. deg2rad dq      3f91df46a2529d39h       ; 2 * pi / 360
  191.  
  192. arg     dq      0                       ; angle in radians
  193.  
  194. inbuff  db      80 dup (?)              ; keyboard input buffer
  195.  
  196. _DATA   ends
  197.  
  198.  
  199. STACK   segment para stack 'STACK'
  200.         
  201.         db      128 dup (?)
  202.  
  203. STACK   ends
  204.  
  205.         end     main
  206.  
  207.